<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="小区名称" prop="buildingName">
        <el-input
          v-model="queryParams.buildingName"
          placeholder="请输入小区名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="户型面积" prop="unitArea">
        <el-input
          v-model="queryParams.unitArea"
          placeholder="请输入户型面积"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总价(万元)" prop="totalFee">
        <el-input
          v-model="queryParams.totalFee"
          placeholder="请输入总价(万元)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单价(元)" prop="unitPrice">
        <el-input
          v-model="queryParams.unitPrice"
          placeholder="请输入单价(元)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否满两年" prop="twoFlg">
        <el-input
          v-model="queryParams.twoFlg"
          placeholder="请输入是否满两年"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否满五年" prop="fiveFlg">
        <el-input
          v-model="queryParams.fiveFlg"
          placeholder="请输入是否满五年"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否唯一" prop="onlyFlg">
        <el-input
          v-model="queryParams.onlyFlg"
          placeholder="请输入是否唯一"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据来源" prop="source">
        <el-input
          v-model="queryParams.source"
          placeholder="请输入数据来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['kanfang:info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="小区名称" align="center" prop="buildingName" />
      <el-table-column label="标题" align="center" prop="title" />
	  <el-table-column label="详情链接" align="center" width="110">
	      <template slot-scope="scope">  
	        <a :href="scope.row.buildingDetailUrl" target="_blank">查看详情</a>  
	      </template>  
	  </el-table-column> 
      <el-table-column label="户型介绍" align="center" prop="houseInfo" />
      <el-table-column label="楼层类型" align="center" prop="floorType" />
      <el-table-column label="总楼层" align="center" prop="floorCount" />
      <el-table-column label="户型面积" align="center" prop="unitArea" />
      <el-table-column label="总价(万元)" align="center" prop="totalFee" width="120"/>
      <el-table-column label="单价(元)" align="center" prop="unitPrice" />
      <el-table-column label="户型" align="center" prop="houseType" />
      <el-table-column label="朝向" align="center" prop="facing" />
      <el-table-column label="关注人数" align="center" prop="starNum" />
      <el-table-column label="发布时间" align="center" prop="issueTime" />
      <el-table-column label="年份" align="center" prop="years" />
      <el-table-column label="是否满两年" align="center" prop="twoFlg" width="120"/>
      <el-table-column label="是否满五年" align="center" prop="fiveFlg" width="120"/>
      <el-table-column label="是否唯一" align="center" prop="onlyFlg" />
	  <el-table-column label="降价(万)" align="center" prop="priceReduce" />
	  <el-table-column label="降价时间" align="center" prop="reduceTm" />
      <el-table-column label="标签" align="center" prop="tag" />
      <el-table-column label="数据来源" align="center" prop="source" />
      <el-table-column label="创建时间" align="center" prop="createTm" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTm, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTm" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTm, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['kanfang:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['kanfang:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商品房信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="小区名称" prop="buildingName">
          <el-input v-model="form.buildingName" placeholder="请输入小区名称" />
        </el-form-item>
        <el-form-item label="销售名" prop="sellName">
          <el-input v-model="form.sellName" placeholder="请输入销售名" />
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="详情链接" prop="buildingDetailUrl">
          <el-input v-model="form.buildingDetailUrl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="户型介绍" prop="houseInfo">
          <el-input v-model="form.houseInfo" placeholder="请输入户型介绍" />
        </el-form-item>
        <el-form-item label="总楼层" prop="floorCount">
          <el-input v-model="form.floorCount" placeholder="请输入总楼层" />
        </el-form-item>
        <el-form-item label="户型面积" prop="unitArea">
          <el-input v-model="form.unitArea" placeholder="请输入户型面积" />
        </el-form-item>
        <el-form-item label="总价(万元)" prop="totalFee">
          <el-input v-model="form.totalFee" placeholder="请输入总价(万元)" />
        </el-form-item>
        <el-form-item label="单价(元)" prop="unitPrice">
          <el-input v-model="form.unitPrice" placeholder="请输入单价(元)" />
        </el-form-item>
        <el-form-item label="朝向" prop="facing">
          <el-input v-model="form.facing" placeholder="请输入朝向" />
        </el-form-item>
        <el-form-item label="关注人数" prop="starNum">
          <el-input v-model="form.starNum" placeholder="请输入关注人数" />
        </el-form-item>
        <el-form-item label="发布时间" prop="issueTime">
          <el-input v-model="form.issueTime" placeholder="请输入发布时间" />
        </el-form-item>
        <el-form-item label="年份" prop="years">
          <el-input v-model="form.years" placeholder="请输入年份" />
        </el-form-item>
        <el-form-item label="是否满两年" prop="twoFlg">
          <el-input v-model="form.twoFlg" placeholder="请输入是否满两年" />
        </el-form-item>
        <el-form-item label="是否满五年" prop="fiveFlg">
          <el-input v-model="form.fiveFlg" placeholder="请输入是否满五年" />
        </el-form-item>
        <el-form-item label="是否唯一" prop="onlyFlg">
          <el-input v-model="form.onlyFlg" placeholder="请输入是否唯一" />
        </el-form-item>
        <el-form-item label="标签" prop="tag">
          <el-input v-model="form.tag" placeholder="请输入标签" />
        </el-form-item>
		<el-form-item label="降价(万)" prop="priceReduce">
		  <el-input v-model="form.priceReduce" placeholder="请输入标签" />
		</el-form-item>
        <el-form-item label="数据来源:1-贝壳" prop="source">
          <el-input v-model="form.source" placeholder="请输入数据来源:1-贝壳" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createTm">
          <el-date-picker clearable
            v-model="form.createTm"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新时间" prop="updateTm">
          <el-date-picker clearable
            v-model="form.updateTm"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/kanfang/info";

export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品房信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        buildingName: null,
        title: null,
        buildingDetailUrl: null,
        houseInfo: null,
        floorType: null,
        floorCount: null,
        unitArea: null,
        totalFee: null,
        unitPrice: null,
        houseType: null,
        facing: null,
        starNum: null,
        issueTime: null,
        years: null,
        twoFlg: null,
        fiveFlg: null,
        onlyFlg: null,
        tag: null,
        source: null,
        createTm: null,
        updateTm: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        buildingName: [
          { required: true, message: "小区名称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商品房信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        buildingName: null,
        sellName: null,
        title: null,
        buildingDetailUrl: null,
        houseInfo: null,
        floorType: null,
        floorCount: null,
        unitArea: null,
        totalFee: null,
        unitPrice: null,
        houseType: null,
        facing: null,
        starNum: null,
        issueTime: null,
        years: null,
        twoFlg: null,
        fiveFlg: null,
        onlyFlg: null,
        tag: null,
        source: null,
        createTm: null,
        updateTm: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商品房信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商品房信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除商品房信息编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('kanfang/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
